package com.ruoyi.book.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.book.domain.Bookreturn;
import com.ruoyi.book.service.IBookreturnService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 还书管理Controller
 *
 * @author ruoyi
 * @date 2022-12-30
 */
@RestController
@RequestMapping("/book/bookreturn")
public class BookreturnController extends BaseController
{
    @Autowired
    private IBookreturnService bookreturnService;


    @GetMapping("/getListByUserId")
    public TableDataInfo getListByUserId(Bookreturn bookreturn)
    {
        startPage();
        List<Bookreturn> list = bookreturnService.getListByUserId(bookreturn);
        return getDataTable(list);
    }

    /**
     * 查询还书管理列表
     */
//    @PreAuthorize("@ss.hasPermi('book:bookreturn:list')")
    @GetMapping("/list")
    public TableDataInfo list(Bookreturn bookreturn)
    {
        startPage();
        List<Bookreturn> list = bookreturnService.selectBookreturnList(bookreturn);
        return getDataTable(list);
    }

    /**
     * 导出还书管理列表
     */
//    @PreAuthorize("@ss.hasPermi('book:bookreturn:export')")
    @Log(title = "还书管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Bookreturn bookreturn)
    {
        List<Bookreturn> list = bookreturnService.selectBookreturnList(bookreturn);
        ExcelUtil<Bookreturn> util = new ExcelUtil<Bookreturn>(Bookreturn.class);
        util.exportExcel(response, list, "还书管理数据");
    }

    /**
     * 获取还书管理详细信息
     */
//    @PreAuthorize("@ss.hasPermi('book:bookreturn:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bookreturnService.selectBookreturnById(id));
    }

    /**
     * 新增还书管理
     */
//    @PreAuthorize("@ss.hasPermi('book:bookreturn:add')")
    @Log(title = "还书管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Bookreturn bookreturn)
    {
        return toAjax(bookreturnService.insertBookreturn(bookreturn));
    }

    /**
     * 修改还书管理
     */
//    @PreAuthorize("@ss.hasPermi('book:bookreturn:edit')")
    @Log(title = "还书管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Bookreturn bookreturn)
    {
        return toAjax(bookreturnService.updateBookreturn(bookreturn));
    }

    /**
     * 删除还书管理
     */
//    @PreAuthorize("@ss.hasPermi('book:bookreturn:remove')")
    @Log(title = "还书管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bookreturnService.deleteBookreturnByIds(ids));
    }
}
